package com.shop2cn.iapi.sqdistributor.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.sqdistributor.parameter.request.DeleteDistributorAndConsumerRelationReq;
import com.shop2cn.iapi.sqdistributor.service.DeleteDistributorAndConsumerRelationCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.sqdistributor.DistributorConsumerRelation;
import com.ymttest.database.sqlwapper.sqdistributor.DistributorConsumerRelationWrapper;

public class Ts_DeleteDistributorAndConsumerRelation {
	
	//java接口
	private static DeleteDistributorAndConsumerRelationReq deleteDistributorAndConsumerRelationReq;
	private static DeleteDistributorAndConsumerRelationCall deleteDistributorAndConsumerRelationCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("删除分销员和消费者间绑定关系");
	}

	@Before
	public void caseUp() {
		deleteDistributorAndConsumerRelationReq = new DeleteDistributorAndConsumerRelationReq();
		deleteDistributorAndConsumerRelationCall = new DeleteDistributorAndConsumerRelationCall();	
	}
	
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(deleteDistributorAndConsumerRelationCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	public void verifyDb() throws Exception {
		
		DistributorConsumerRelationWrapper distributorConsumerRelationWrapper = new DistributorConsumerRelationWrapper();

		DistributorConsumerRelation actualResult = distributorConsumerRelationWrapper
				.selectByPrimaryKey(deleteDistributorAndConsumerRelationReq
						.getId());

		Logger.verifyEquals(true, actualResult.getIs_deleted(), "验证Is_deleted");
		
		distributorConsumerRelationWrapper.updateDeleteToFalse(deleteDistributorAndConsumerRelationReq.getId());
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DeleteDistributorAndConsumerRelation_001() {
		Logger.start(true, "删除分销员和消费者间绑定关系");
		
		try {
			
			deleteDistributorAndConsumerRelationReq.setId(3L);
			
			deleteDistributorAndConsumerRelationCall.setData(deleteDistributorAndConsumerRelationReq);
			deleteDistributorAndConsumerRelationCall.callService();
			
			Logger.verifyEquals(true, deleteDistributorAndConsumerRelationCall.getSuccess(), "验证success");
			
			verifyDb();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_DeleteDistributorAndConsumerRelation_002() {
		Logger.start(true, "id为null，删除失败");

		try {

			// deleteDistributorAndConsumerRelationReq.setId(3L);

			deleteDistributorAndConsumerRelationCall
					.setData(deleteDistributorAndConsumerRelationReq);
			deleteDistributorAndConsumerRelationCall.callService();

			Logger.verifyEquals(false,
					deleteDistributorAndConsumerRelationCall.getSuccess(),
					"验证success");
			Logger.verifyEquals("id:must be greater than or equal to 1",
					deleteDistributorAndConsumerRelationCall.getMsg(),
					"验证resultMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
